import { reactive, ref } from 'vue'
import { defineStore } from 'pinia'
export const useSettingData = defineStore('settingData', () => {
  interface threshold {
    min?: number
    minmsg?: string
    max?: number
    maxmsg?: string
  }

  const deviceid = ref(0)
  let deviceList = ['监测1', '监测2', '监测3']
  const deviceChoose = ref('监测1')
  let time = ref('白昼')

  let thresholdName = {
    监测1: ['空气温度', '空气湿度', '光照强度', '风向', '风速', '雨量', '日累计雨量'],
    监测2: ['ph值', '溶解氧', '水温'],
    监测3: ['没想好'],
  }

  const min = reactive([])
  const minmsg = reactive([])
  const max = reactive([])
  const maxmsg = reactive([])

  function clearInsert() {
    min.length = 0
    max.length = 0
    minmsg.length = 0
    maxmsg.length = 0
    thresholdData.length = 0
  }

  const thresholdData: threshold[] = [{}]

  function getAllData() {
    for (let i = 0; i < min.length; i++) {
      thresholdData.push({
        min: min[i],
        max: max[i],
        minmsg: minmsg[i],
        maxmsg: maxmsg[i],
      })
    }
  }

  return {
    deviceList,
    time,
    thresholdName,
    deviceChoose,
    deviceid,
    thresholdData,
    min,
    minmsg,
    max,
    maxmsg,
    getAllData,
    clearInsert,
  }
})

export const useStrategyData = defineStore('strategyData', () => {
  const deviceList = reactive(['监测1', '监测2', '监测3'])

  return { deviceList }
})

export const useRecordData = defineStore('recordData', () => {
  const deviceList = reactive(['监测1', '监测2', '监测3'])

  return { deviceList }
})
